package groep3.ssc.skaterViews;

import groep3.ssc.main.R;
import groep3.ssc.model.Race;
import groep3.ssc.skaterViews.DirectionArrow.Arrow;
import groep3.ssc.skaterViews.DirectionArrow.LeftArrow;
import groep3.ssc.skaterViews.DirectionArrow.RightArrow;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class DirectionView extends SkaterViewTemplate
{
    public Arrow arrow;
    private Paint paint;

    public DirectionView(Context context)
    {
        super(context);
        setWillNotDraw(false);
        this.setActivated(true);

        LayoutParams params = new LayoutParams(400, 400);
        setLayoutParams(params);
        invalidate();
    }

    @Override
    public void update(Race model)
    {
        if (model.getSkaters() == null || model.getSkaters().size() <= 0)
            return;

        switch (model.getSkaters().get(model.getOurSkater()).getLane())
        {
            case INNER:
                arrow = new LeftArrow(getWidth(), getHeight());
                break;
            case OUTER:
                arrow = new RightArrow(getWidth(), getHeight());
                break;
        }

        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        if (controller == null)
            subscribeToController();

        if (arrow == null)
        {
            super.onDraw(canvas);
            return;
        }

        if (paint == null)
            paint = new Paint();

        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(10);

        canvas.drawPath(arrow.getPath(), paint);
        canvas.drawPath(arrow.getRect(), paint);

        super.onDraw(canvas);
    }

    @Override
    public String toString()
    {
        Resources res = getResources();
        String directionViewString = res.getString(R.string.txtDirectionViewString);
        return directionViewString;
    }
}
